//判断用户名是邮箱还是用户名，根据不同情况脱敏显示
export function formatUserIdentifier(identifier) {
  if (!identifier) return '-'
  if (identifier.includes('@')) {
    // 是邮箱地址
    const atIndex = identifier.indexOf('@')
    const prefix = identifier.substring(0, atIndex)
    const suffix = identifier.substring(atIndex + 1)
    return '*'.repeat(prefix.length) + '@' + suffix
  } else {
    // 是用户名
    if (identifier.length > 6) {
      const front = identifier.substring(0, 3)
      const back = identifier.substring(identifier.length - 3)
      // const middle = '*'.repeat(identifier.length - 6)
      const middle = '*'.repeat(3)
      return front + middle + back
    } else if (identifier.length <= 6 && identifier.length > 4) {
      const front = identifier.substring(0, 2)
      const back = identifier.substring(identifier.length - 2)
      const middle = '*'.repeat(3)
      return front + middle + back
    } else if (identifier.length <= 4 && identifier.length > 2) {
      const front = identifier.charAt(0)
      const back = identifier.charAt(identifier.length - 1)
      const middle = '*'.repeat(3)
      return front + middle + back
    } else {
      const front = identifier.substring(0, 1)
      return front + '*'
    }
  }
}
